package com.lamp.main;


import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.google.android.c2dm.C2DMBaseReceiver;

public class C2DMReceiver extends C2DMBaseReceiver {

	public C2DMReceiver() {
		super("lamp.c2dm@gmail.com");
	}

	@Override
	public void onRegistered(Context context, String registrationId) {
		Log.i("------------dfdf-d------------------", "------------onRegistered------------------");
		Log.w("C-2DMReceiver-onRegistered", registrationId);
		postData(registrationId);
	}

	@Override
	public void onUnregistered(Context context) {
		Log.i("------------dfdf-d------------------", "------------onUnregistered------------------");
		Log.w("C2DMReceiver-onUnregistered", "got here!");
	}

	@Override
	public void onError(Context context, String errorId) {
		Log.w("C2DMReceiver-onError", errorId);
		Log.i("------------dfdf-d------------------", "------------onError------------------");
		Toast.makeText(context, "Push notification error: " + errorId, 3000).show();
	}

	@Override
	protected void onMessage(Context context, Intent intent) {
		Log.w("C2DMReceiver","-------------C2DMReceiver------------------");
		Log.w("C2DMReceiver", intent.getStringExtra("message"));
		String msg = null;		
	}

	public void postData(String registrationId) {
		
	/*	 try {
			 String a = "http://10.0.0.1/webservice/search.php?keyword=";
		        HttpClient client = new DefaultHttpClient();  
		        String postURL = "http://slide.mn/push/amar/index.php";
		        HttpPost post = new HttpPost(postURL); 
		            List<NameValuePair> params = new ArrayList<NameValuePair>();
		            params.add(new BasicNameValuePair("apikey","1"));	
		            params.add(new BasicNameValuePair("email",AmarActivity.account.name));
		            params.add(new BasicNameValuePair("deviceToken", registrationId));
		            UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
		            post.setEntity(ent);
		            HttpResponse responsePOST = client.execute(post);  
		            HttpEntity resEntity = responsePOST.getEntity();  
		            if (resEntity != null) {    
		                Log.i("RESPONSE",EntityUtils.toString(resEntity));
		            }
		    } catch (Exception e) {
		        e.printStackTrace();
		    }*/
	}
}